package breeze.pixel.weather.apps_util.views.mtoolbar;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import breeze.pixel.weather.R;
import breeze.pixel.weather.apps_util.views.mtextview.MTextView;

public class MToolbar extends LinearLayout {
    public MToolbar(Context context) {
        super(context);
        init(context);
    }
    public MToolbar(Context context, AttributeSet attr, int i){
        super(context,attr,i);
        init(context);
        initByAttr(context, attr);
    }
    public MToolbar(Context context,AttributeSet attr){
        super(context,attr);
        init(context);
        initByAttr(context, attr);
    }

    private MTextView mTitle,mSubTitle;
    private ImageView mNavigation,mImg1,mImg2,mImg3;
    private void init(Context context){
        View baseView = LayoutInflater.from(context).inflate(R.layout.view_toolbar, this);
        this.mSubTitle = baseView.findViewById(R.id.viewtoolbarTextView2);
        this.mTitle = baseView.findViewById(R.id.viewtoolbarTextView1);
        this.mNavigation = baseView.findViewById(R.id.viewtoolbar_img_negative);
        this.mImg1 = baseView.findViewById(R.id.viewtoolbarImageView1);
        this.mImg2 = baseView.findViewById(R.id.viewtoolbarImageView2);
        this.mImg3 = baseView.findViewById(R.id.viewtoolbarImageView3);
    }

    private void initByAttr(Context context,AttributeSet set){
        @SuppressLint("Recycle")
        TypedArray attributes = context.obtainStyledAttributes(set,R.styleable.MToolbar);
        String title = attributes.getString(R.styleable.MToolbar_title);
        String subTitle = attributes.getString(R.styleable.MToolbar_subtitle);
        setTitle(title);
        setSubTitle(subTitle);
    }

    public void setTitle(String text){
        if(text!=null) {
            this.mTitle.setVisibility(View.VISIBLE);
            this.mTitle.setText(text);
        }
    }

    public void setSubTitle(String text){
        if(text!=null) {
            this.mSubTitle.setVisibility(View.VISIBLE);
            this.mSubTitle.setText(text);
        }
    }

    public void setNavigation(int resID,OnClickListener onClick){
        this.mNavigation.setVisibility(View.VISIBLE);
        this.mNavigation.setImageResource(resID);
        this.mNavigation.setOnClickListener(onClick);
    }

    public void setImg1(int resID,OnClickListener onClick){
        this.mImg1.setVisibility(View.VISIBLE);
        this.mImg1.setImageResource(resID);
        this.mImg2.setOnClickListener(onClick);
    }

    public void setImg2(int resID,OnClickListener onClick){
        this.mImg2.setVisibility(View.VISIBLE);
        this.mImg2.setImageResource(resID);
        this.mImg2.setOnClickListener(onClick);
    }

    public void setImg3(int resID,OnClickListener onClick){
        this.mImg3.setVisibility(View.VISIBLE);
        this.mImg3.setImageResource(resID);
        this.mImg3.setOnClickListener(onClick);
    }
}
